/*
 * Copyright 2012 Alan Burlison, alan@bleaklow.com.  All rights reserved.
 * Use is subject to license terms.  See LICENSE.txt for details.
 */

#include "utils.h"
#include "clock.h"
#include "TaskScheduler.h"

TaskScheduler::TaskScheduler(Task **_tasks, uint8_t _numTasks) :
  tasks(_tasks),
  numTasks(_numTasks) {
}

void TaskScheduler::run() {
    for (;;) {
        uint32_t now = millis();
        Task **tpp = tasks;
        for (uint8_t t = numTasks; t > 0; t--) {
            if ((*tpp)->run(now)) {
                break;
            }
            tpp++;
        }
    }
}
